Support --target with `cargo test`
authorAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:12:32 +0000 (21:12 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:12:32 +0000 (21:12 -0700)
Closes #356

src/bin/cargo-test.rs
tests/test_cargo_cross_compile.rs

index 522b77735d248d0d718e6d94be7a035dca853b80..cd3628dbefa45fe9b79e489332c29a19b86bca73 100644 (file)
@@ -22,6 +22,7 @@ Usage:
 Options:
     -h, --help              Print this message
     -j N, --jobs N          The number of jobs to run in parallel
+    --target TRIPLE         Build for the target triple
     -u, --update-remotes    Deprecated option, use `cargo update` instead
     --manifest-path PATH    Path to the manifest to build tests for
     -v, --verbose           Use verbose output
@@ -44,7 +45,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
         env: "test",
         shell: shell,
         jobs: options.flag_jobs,
-        target: None,
+        target: options.flag_target.as_ref().map(|s| s.as_slice()),
     };
 
     let err = try!(ops::run_tests(&root, &mut compile_opts,
index 08c4d6837c541aef7d7d5859f820111f9e1276a1..6a3bcc49f4720453ed2c5cab5982713650d1dcb4 100644 (file)
@@ -7,7 +7,7 @@ use std::os;
 use std::path;
 
 use support::{project, execs, basic_bin_manifest};
-use support::{RUNNING, COMPILING, cargo_dir};
+use support::{RUNNING, COMPILING, DOCTEST, cargo_dir};
 use hamcrest::{assert_that, existing_file};
 use cargo::util::process;
 
@@ -337,3 +337,54 @@ test!(plugin_with_extra_dylib_dep {
     assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target),
                 execs().with_status(0));
 })
+
+test!(cross_tests {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            authors = []
+            version = "0.0.0"
+        "#)
+        .file("src/main.rs", r#"
+            extern crate foo;
+            use std::os;
+            fn main() {
+                assert_eq!(os::consts::ARCH, "x86");
+            }
+            #[test] fn test() { main() }
+        "#)
+        .file("src/lib.rs", r#"
+            use std::os;
+            pub fn foo() { assert_eq!(os::consts::ARCH, "x86"); }
+            #[test] fn test_foo() { foo() }
+        "#);
+
+    let target = alternate();
+    assert_that(p.cargo_process("cargo-test").arg("--target").arg(target),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+{compiling} foo v0.0.0 ({foo})
+{running} target[..]{triple}[..]test[..]foo-[..]
+
+running 1 test
+test test ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+{running} target[..]{triple}[..]test[..]foo-[..]
+
+running 1 test
+test test_foo ... ok
+
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} foo
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target,
+   doctest = DOCTEST)));
+})